package com.testingedu.action.background;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.testingedu.common.QueryResult;
import com.testingedu.model.TUser;

public class RequestContext implements java.io.Serializable{
	private static final long serialVersionUID = -8594925806318338757L;
	public HttpServletRequest request;
	public HttpServletResponse response;
	public ServletContext servletContext;
	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}
	public QueryResult queryResult;
	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}
	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}
	
	public void createQueryResult() {
		queryResult = new QueryResult();
		String currentPage = request.getParameter("_currentPage");
		if (currentPage != null && currentPage.length() > 0) {
			queryResult.setCurrentPage(Long.parseLong(currentPage));
		}
	}
	
	public TUser getTUser() {
		Object tUser = request.getSession().getAttribute("testingedu_admin");
		if(tUser != null) {
			return (TUser)tUser;
		}
		return null;
	}
	
	public Integer getTUserId() {
		TUser tUser = getTUser();
		if(tUser != null) {
			return tUser.getId();
		}
		return 0;
	}
	
}
